package com.kk.crowd.service.impl;

import com.kk.crowd.entity.po.MemberPO;
import com.kk.crowd.entity.po.MemberPOExample;
import com.kk.crowd.mapper.MemberPOMapper;
import com.kk.crowd.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true)
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberPOMapper memberPOMapper;

    @Override
    public MemberPO getMemberPOByLoginAcct(String loginacct) {
        //  1、创建Example对象
        MemberPOExample memberPOExample = new MemberPOExample();

        //  2、创建Criteria对象
        MemberPOExample.Criteria criteria = memberPOExample.createCriteria();

        //  3、封装查询条件
        criteria.andLoginacctEqualTo(loginacct);

        //  4、执行查询
        List<MemberPO> memberPOList = memberPOMapper.selectByExample(memberPOExample);

        //  5、返回结果
        return memberPOList.get(0);
    }

    @Override
    @Transactional(
            propagation = Propagation.REQUIRES_NEW,
            rollbackFor = Exception.class,
            readOnly = false)
    public void saveMember(MemberPO memberPO) {
        memberPOMapper.insertSelective(memberPO);
    }
}
